<?php

class Sc_Service_Comment extends Sc_Service_Abstract
{
	public function listComment($vn, $jp, $username) {
		try {
            $db = new Sc_Db_Comment();
            return $db->getComment($vn, $jp, $username);
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
	}

	public function addComment($comment)
	{
		$ret = false;
		$this->beginTransaction();
		try {
            $db = new Sc_Db_Comment();
            $comment->datecreated = new Zend_Db_Expr('CURRENT_TIMESTAMP');

            $ret = $db->insertRecord($comment);

            $this->commit();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        return $ret;
	}

	public function editComment($comment)
	{
		$ret = false;
		$this->beginTransaction();
		try {
            $db = new Sc_Db_Comment();
            $ret = $db->updateComment($comment);

            $this->commit();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        return $ret;
	}

	public function deleteComment($comment)
	{
		$ret = false;
		$this->beginTransaction();
		try {
            $db = new Sc_Db_Comment();
            $ret = $db->deleteComment($comment);

            $this->commit();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        return $ret;
	}

	public function getCommentById($id)
	{
		$ret = false;
		try {
            $db = new Sc_Db_Comment();
            $ret = $db->getCommentById($id);
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        return  $ret;
	}
}